package com.tanhua.server.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.tanhua.server.service.TestSoulService;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {
    @Autowired
    private TestSoulService testSoulService;
    /**
     * 测灵魂
     * @return
     */
    @GetMapping
    public ResponseEntity testSoullist(){
        return testSoulService.testSoullist();
    }
    /**
     * 提交数据
     * @param map
     * @return
     */
    @PostMapping
    public ResponseEntity submitTestSoul( @RequestBody Map map){
       List answers = (List) map.get("answers");
       List<String> questionIds= new ArrayList<>();
       List<String> optionIds = new ArrayList<>();
        for (int i = 0; i < answers.size(); i++) {
            Map map1 = (Map) answers.get(i);
            String questionId = (String) map1.get("questionId");
            String optionId = (String) map1.get("optionId");
            questionIds.add(questionId);
            optionIds.add(optionId);
        }

        return testSoulService.submitTestSoul(questionIds,optionIds) ;
    }
    /**
     * 查询结果
     * @param reportId 报告id
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity SearchResult(@PathVariable("id") String reportId){
      return   testSoulService.SearchResult(reportId);
    }
}
